package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// FloorBrand 楼层品牌
type FloorBrand struct {
	ID                    string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	FloorID               string `json:"floor_id" gorm:"column:floor_id;index:floor_id;type:int;size:64;comment:楼层id"`
	BrandID               string `json:"brand_id" gorm:"column:brand_id;index:brand_id;type:int;size:64;comment:品牌id"`
	Recommended           int    `json:"recommended" gorm:"column:recommended;type:int;size:8;comment:是否推荐"`
	SearchRecommended     int    `json:"search_recommended" gorm:"column:search_recommended;type:int;size:8;comment:是否搜索推荐"`
	RecommendedSort       int    `json:"recommended_sort" gorm:"column:recommended_sort;type:int;size:16;default:1000;comment:推荐排序"`
	SearchRecommendedSort int    `json:"search_recommended_sort" gorm:"column:search_recommended_sort;type:int;size:16;default:1000;comment:搜索推荐排序"`
	PositionID            string `json:"position_id" gorm:"column:position_id;index:position_id;type:string;size:40;comment:位置id"`
	ContactPhone          string `json:"contact_phone" gorm:"column:contact_phone;type:string;size:40;comment:联系电话"`
	ShopNO                string `json:"shop_no" gorm:"column:shop_no;type:string;size:40;comment:店铺铺号"`
	CreatedAt             int64  `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt             int64  `json:"updated_at,omitempty" gorm:"column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (FloorBrand) TableName() string {
	return "floor_brand"
}

// BeforeCreate 自增id
func (l *FloorBrand) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &FloorBrand{})
}
